﻿using MediatR;
using Microsoft.Extensions.Logging;
using Ordering.Domain.Events;

namespace Ordering.Application.DomainEvents
{
    /// <summary>
    /// 不建议，因为发布领域事件是在事务提交之前，事务有提交失败的可能性
    /// </summary>
    internal class SendEmailOrderDomainEventHandler
        : INotificationHandler<CreateOrderDomainEvent>
    {
        private readonly ILogger _logger;

        public SendEmailOrderDomainEventHandler(ILogger<SendEmailOrderDomainEventHandler> logger)
        {
            _logger = logger;
        }

        public Task Handle(CreateOrderDomainEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("订单已创建，请及时支付：" + notification.Target.Id);
            return Task.CompletedTask;
        }
    }
}
